package com.algomypractice.sort;

import com.algomypractice.binary.Search;
import com.algomypractice.sort.timecomplexityon2.BubbleSort;
import com.algomypractice.sort.timecomplexityon2.MergeSort;

import java.util.Arrays;
import java.util.Random;

/**
 * @author: ZhouBert
 * @date: 2019/6/12
 * @description: 排序测试（最终结果是从小到大）
 */
public class SortTester {

	static int size = 100;

	public static void main(String[] args) {

		//region 生成随机数组
		int[] arr = new int[size];
		Random random = new Random();
		for (int i = 0; i < size; i++) {
			arr[i] = random.nextInt(size);
		}
		//endregion

		System.out.println(Arrays.toString(arr));
		//region 拷贝数组
		int[] arr2 = Arrays.copyOf(arr, size);
		int[] arr3 = Arrays.copyOf(arr, size);
		int[] arr4 = Arrays.copyOf(arr, size);
		int[] arr5 = Arrays.copyOf(arr, size);
		int[] arr6 = Arrays.copyOf(arr, size);
		//endregion

		///InsertionSort.directInsertionSort(arr3);
		///SelectionSort.selectionSort(arr3);
		///InsertionSort.binaryInsertionSort(arr3);
		///InsertionSort.shellSedgeWickSort(arr3);
		//QuickSort.quickSortByDigHole(arr3);
		///InsertionSort.shellSort(arr3);
		MergeSort.mergeSort(arr3);
		System.out.println(Arrays.toString(arr3));
		///二分查找
		System.out.println(Search.bsearch(arr3, arr3.length, arr3[7]));
		System.out.println(Search.bssearchByRecursion(arr3, 0, arr3.length-1, arr3[5]));

		//region 测试普通冒泡排序时间
		long time1 = System.currentTimeMillis();
		BubbleSort.bubbleSort(arr2);
		System.out.println(System.currentTimeMillis()-time1+" ms");
		System.out.println(Arrays.toString(arr2));
		//endregion

		//region 测试优化冒泡排序时间

		//endregion


	}


}
